package rule.rulechain;

import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

import java.io.File;
import java.io.IOException;

/**
 * Created by fengxiangxiang on 2016-10-14.
 */
public class CreateFile implements TestRule {

    public CreateFile(String path,String fileName){
        // 创建一个新的文件，文件名即是传入的 fileName 值
        File f = new File(path);
        if (!f.exists()){
            f.mkdirs();
        }
        File file = new File(f,fileName);
        if (!file.exists()){
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        System.out.println("start creating file");

    }

    @Override
    public Statement apply(final Statement base,final Description description) {
        System.out .println("Step2:New file is created");
        return base;
    }
}
